package com.example.listview;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;

public class MainActivity extends AppCompatActivity {
    static final String TAG="ListViewSample";
    String[]DATA={"北京","天津","上海","重庆","乌鲁木齐"};
    int[]icons={R.mipmap.ic_launcher,R.mipmap.ic_launcher_round,
            R.mipmap.ic_launcher_round,R.mipmap.ic_launcher_round,R.mipmap.ic_launcher};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EfficientAdapter adapter = new EfficientAdapter(this,
                R.layout.listview_item,DATA,icons);
        ListView listview=(ListView)findViewById(R.id.listview);
        listview.setAdapter((ListAdapter) adapter);
        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Log.i(TAG,"选择："+DATA[i]);
            }
        });

    }
}